//
//  ByUISafetyIndexVC.m
//  chequanbao_ios
//
//  Created by pro on 17/5/6.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUISafetyIndexVC.h"

// vc
#import "ByUIPropertySafetyVC.h"

@interface ByUISafetyIndexVC ()

@end

@implementation ByUISafetyIndexVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addLeftBackBarButtonItem];

    self.title = @"保险超市";
    self.view.backgroundColor = [UIColor greenColor];
    
    [self createViews];
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self setNaviAttributeWithTranslucent:YES stateBarLightContent:YES];
}

- (void)viewSafeAreaInsetsDidChange{
    [super viewSafeAreaInsetsDidChange];
    UIImageView *img = [self.view viewWithTag:10];
    img.top = self.view.safeAreaInsets.top;
}

- (void)createViews {
    
    CGFloat x, y, width, height;
    CGFloat margin_h = 15, margin_v = 20;
    
//    NSArray *titles = @[@"我的车险", @"人寿保险", @"健康保险", @"养老保险"];
//    NSArray *images = @[@"Safety_caichan",@"Safety_renshou",@"Safety_jiankang",@"Safety_yanglao"];
    
    
    NSArray *titles = @[@"我的车险"];
    NSArray *images = @[@"Safety_caichan"];

    NSArray *colors = @[rgba(11, 48, 84, 1),
                        rgba(184, 0, 48, 1),
                        rgba(25, 76, 153, 1),
                        rgba(224, 0, 40, 1),];
    for (int i = 0; i < titles.count; i ++) {
        
        width = SCREEN_WIDTH - margin_h * 2;
        height = (SCREEN_HEIGHT - 64 - margin_v * 4) / 4;
        x = margin_h;
        y = 64 + (margin_v + height) * i;
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, width, height)];
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:images[i]];
        [self.view addSubview:imageView];
        imageView.layer.cornerRadius = 5;
        imageView.layer.masksToBounds = YES;
        imageView.tag = i + 10;
        
        width *= 0.4;
        height *= 0.6;
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, height)];
        label.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4];
        label.font = FONT(MIN(25, width / 5));
        label.text = titles[i];
        label.textColor = colors[i];
        label.textAlignment = NSTextAlignmentCenter;
        [imageView addSubview:label];
        label.layer.cornerRadius = 5;
        label.layer.borderColor = label.textColor.CGColor;
        label.layer.borderWidth = 2;
        label.x = imageView.width / 2;
        label.y = imageView.height / 2;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [imageView addGestureRecognizer:tap];
        
    }
}

- (void)tapAction:(UITapGestureRecognizer *)tap {
    if (tap.view.tag == 10) {
        if (!BY_USER) {
            ByUILoginVC *vc = [[ByUILoginVC alloc] init];
            ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:vc];
            [self presentViewController:navi animated:YES completion:nil];
            return;
        }
    }
    switch (tap.view.tag) {
        case 10:
        {
            ByUIPropertySafetyVC *vc = [[ByUIPropertySafetyVC alloc] init];
            [self by_normalPush:vc hasNavi:YES];
        }
            break;
            
        default:
            break;
    }
}

@end
